/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler;

import com.funcom.peeler.symbol.Symbol;
import com.jme.renderer.ColorRGBA;
import com.jmex.bui.border.EmptyBorder;
import com.jmex.bui.border.LineBorder;
import com.jmex.bui.property.Property;
import com.jmex.bui.provider.ResourceProvider;

public class BorderProperty extends Property {

    public String sides;
    public String type;
    public int thickness;
    public ColorRGBA color;

    BorderProperty( String sides, String type, int thickness, ColorRGBA color ) {
        this.sides = sides;
        this.type = type;
        this.thickness = thickness;
        this.color = color;
    }

    public Object resolve( ResourceProvider rsrcprv ) {

        int left = thickness, right = thickness,
                top = thickness, bottom = thickness;

        if ( !sides.equals( Symbol.StyleProperty.border_left ) ) {
            left = 0;
        }

        if ( !sides.equals( Symbol.StyleProperty.border_right ) ) {
            right = 0;
        }

        if ( !sides.equals( Symbol.StyleProperty.border_top ) ) {
            top = 0;
        }

        if ( !sides.equals( Symbol.StyleProperty.border_bottom ) ) {
            bottom = 0;
        }

        if ( sides.equals( Symbol.StyleProperty.border ) ) {
            left = right = top = bottom = thickness;
        }

        if ( type.equals( "blank" ) ) {
            return new EmptyBorder( left, top, right, bottom );
        }
        else if ( type.equals( "solid" ) ) {
            return new LineBorder( color, thickness );
        }
        else
        {
            throw new RuntimeException( "Unknown border type " + type );
        }
    }
}
